package jvlite.dao.dataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class ConnectionUtil {

	private static ThreadLocal<Connection> tl = new ThreadLocal<Connection>();
	private static Connection initConn = null;

	static {
		try {
			initConn = DBPool.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConn() {
		Connection c = null;
		if (null == tl.get()) {
			c = initConn;
		} else {
			c = tl.get();
		}
		return c;
	}

	public static void setConn(Connection conn) {
		if (null == conn) {
			tl.set(initConn);
		} else {
			tl.set(conn);
		}
	}

}